local hx__AIDS = fk.CreateSkill{
  name = "hx__AIDS",
  tags = {Skill.Compulsory},
}

hx__AIDS:addAcquireEffect(function (self, player, is_start)
  local room = player.room
  if player.role ~= "lord" then
    room:setPlayerProperty(player,"role","lord")
  end
  if not player:hasSkill("hx__bdcr",true) then
    room:handleAddLoseSkills(player,"hx__bdcr")
  end
end)

hx__AIDS:addEffect(fk.DamageInflicted, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__AIDS.name) and table.find(player.room:getOtherPlayers(player),function(p)
      return not p:hasSkill("hx__mybh",true) and #player.room.logic:getActualDamageEvents(1, function (e)
        local damage = e.data
        return damage.from == player and damage.to == p
      end, Player.HistoryGame) > 0
    end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(player.room:getOtherPlayers(player),function(p) return not p:hasSkill("hx__mybh",true) end)
    for _,p in ipairs(targets) do
      if #player.room.logic:getActualDamageEvents(1, function (e)
        local damage = e.data
        return damage.from == player and damage.to == p
      end, Player.HistoryGame) > 0 then
        room:handleAddLoseSkills(p,"hx__mybh")
      end
    end
  end,
})

hx__AIDS:addEffect(fk.DetermineDamageInflicted, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__AIDS.name) and data.card and not table.contains(player:getTableMark("@$hx__AIDS"),data.card.name) and data.from
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = data.damage
    data:preventDamage()
    for _, p in ipairs(player.room.alive_players) do
      room:damage{
        from = data.from,
        to = p,
        damage = x,
        skillName = hx__AIDS.name,
      }
    end
  end,
})

hx__AIDS:addEffect(fk.Damage, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__AIDS.name) and not table.contains(player:getTableMark("hx__AIDS_num"),data.to.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addTableMarkIfNeed(player,"hx__AIDS_num",data.to.id)
    local mark = #player:getTableMark("hx__AIDS_num")
    room:setPlayerMark(player,"@hx__AIDS_num", mark)
  end,
})


return hx__AIDS